package com.qianfeng.zhangwei.sybl.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.qianfeng.zhangwei.sybl.R;
import com.qianfeng.zhangwei.sybl.bean.Activities;
import com.qianfeng.zhangwei.sybl.utils.ImageLoaderHelper;

import java.util.List;

/**
 * @说 明：
 * @项目名称：Sz1504
 * @包 名： com.qianfeng.zhangwei.sybl.adapter
 * @类 名： ActivityAdapter
 * @创 建人： zhangwei
 * @创建时间：2015-07-29 17:11
 * @版 本：v1.0
 * @修 改人：
 * @修改时间：
 * @修改备注：
 */
public class ActivityAdapter extends AppBaseAdapter<Activities> {
    /**
     * @param list
     * @param context
     */
    public ActivityAdapter(List<Activities> list, Context context) {
        super(list, context);
        options = ImageLoaderHelper.getInstance().getDisplayImageOptions(R.mipmap.ic_android, R.mipmap.ic_android);
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        Activities activities = list.get(position);
        ViewHolder vh;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.adapter_activity_content, parent, false);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }

        ImageLoader.getInstance().displayImage(activities.getHotpic(), vh.img, options);
        vh.nanmeTv.setText(activities.getAname());
        vh.shortNameTv.setText(activities.getShortname());
        vh.joinTv.setText(String.valueOf(activities.getTotal_join_user() + "人参加"));
        vh.statusTv.setText(activities.getStatus());
        String status = activities.getStatus();

        if (!TextUtils.isEmpty(status) && status.equals("已开奖")) {
            vh.statusTv.setBackgroundColor(context.getResources().getColor(R.color.orange));
            vh.statusTv.setText(status);

        } else if (!TextUtils.isEmpty(status) && status.equals("已结束")) {
            vh.statusTv.setBackgroundColor(context.getResources().getColor(R.color.gray));
        } else if (!TextUtils.isEmpty(status) && status.equals("进行中")) {
            vh.statusTv.setBackgroundColor(context.getResources().getColor(R.color.green));
        }
        vh.statusTv.setText(status);
        return convertView;
    }

    private static class ViewHolder {
        private ImageView img;
        private TextView nanmeTv;
        private TextView shortNameTv;
        private TextView joinTv;
        private TextView statusTv;

        public ViewHolder(View convertView) {
            img = (ImageView) convertView.findViewById(R.id.activity_content_icon_img);
            nanmeTv = (TextView) convertView.findViewById(R.id.activity_content_shortname_txt);
            shortNameTv = (TextView) convertView.findViewById(R.id.activity_content_aname_txt);
            joinTv = (TextView) convertView.findViewById(R.id.activity_content_join_txt);
            statusTv = (TextView) convertView.findViewById(R.id.activity_content_status_txt);
        }
    }


}
